#include "NormalizedRandomFunction.h"
#include "../Backpropagation/BackpropagationSynapse.h"
#include "../Backpropagation/ActivationNeuron.h"
#include "../Helper.h"

using namespace NeuralPlusPlus::Core;

NeuralPlusPlus::Core::Initializers::NormalizedRandomFunction::NormalizedRandomFunction()
	{
	}

void NeuralPlusPlus::Core::Initializers::NormalizedRandomFunction::Initialize( Layer *activationLayer )
	{
	Helper::ValidateNotNull(activationLayer, "activationLayer");
	int neuronLength = activationLayer->NeuronsLength;
	double* normalized = Helper::GetRandomVector(neuronLength, 1);
	for (int i=0;i<neuronLength;i++)
		{
		((ActivationNeuron*)(*activationLayer)[i])->Bias = normalized[i];
		}
	delete[] normalized;
	}

void NeuralPlusPlus::Core::Initializers::NormalizedRandomFunction::Initialize( Connector *connector )
	{
	Helper::ValidateNotNull(connector, "connector");
	int synapsesSize = connector->SynapsesLength;
	double* normalized = Helper::GetRandomVector(synapsesSize, 1);
	for(int j=0;j<synapsesSize;j++)
		{
		ISynapse *synapse = &(*connector->Synapses)[j];
		synapse->Weight = normalized[j];
		}
	delete[] normalized;
	}